package OusloginRegister;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.ResultSet;

@WebServlet(name = "OusRegister",urlPatterns = "/ousregister")
public class OusRegister extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        try
        {
            java.sql.Connection conn = null;
            java.sql.Statement sqlStmt = null;
            ResultSet sqlRst = null;
            Class.forName("org.h2.Driver");
            conn =java.sql.DriverManager.getConnection("jdbc:h2:~/jpa-demo-db;MODE=MYSQL;DB_CLOSE_DELAY=-1","sa","sa");
            sqlStmt = conn.createStatement();
            if(request.getParameter("submit")!=null)
            {
                String name = request.getParameter("NAME");
                String phone = request.getParameter("PHONE");
                String password = request.getParameter("PASSWORD");
                String id = request.getParameter("ID");
                String sql = "INSERT INTO CUSTOMER VALUES"+"(" + "'"+id+ "'" +","+"'"+name+"',"+"'"+phone+"',"+"'"+password+"'"+")";
                sqlStmt.executeUpdate(sql);
                response.sendRedirect("http://localhost:8084/index.jsp");
            }
        }
        catch (Exception ex)
        {
            System.out.println(ex.toString());
        }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
